package api

import (
	"FeedXmh/app/dao"
	jwt "github.com/gogf/gf-jwt"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
)

var Menu menu
type menu struct {

}

func (* menu) Get(r *ghttp.Request) {
	claims := jwt.ExtractClaims(r)
	userid := claims["userid"].(string)
	query := ""
	if !dao.T_user.IsAdmin(userid) {
		query += "SELECT DISTINCT t_user_roles.userid,t_func.id,t_func.pid,t_func.url,t_func.icon,t_func.`name`,t_func.name_en,t_func.type,t_func.`order`,t_func.`level`,t_func.default_select FROM t_user_roles "
		query += "INNER JOIN t_permission ON t_user_roles.role_id = t_permission.role_id "
		query += "INNER JOIN t_func ON t_func.id=t_permission.func_id "
		query += "WHERE t_user_roles.userid='" + userid + "' "
		query += "ORDER BY t_func.`level`,t_func.`order` "
	} else {
		query += "SELECT DISTINCT t_func.id,t_func.pid,t_func.url,t_func.icon,t_func.`name`,t_func.name_en,t_func.type,t_func.`order`,t_func.`level`,t_func.default_select FROM t_func "
		query += "ORDER BY t_func.`level`,t_func.`order` "
	}

	//g.Dump(query)
	db:=g.DB("default")
	list, err := db.GetAll(query)
	if err != nil {
		g.Log().Line(true).Error(err.Error())
	}
	r.Response.Write(list.Json())
	r.ExitAll()
}
